<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
{literal}
/* popup_box DIV-Styles*/
#popup_box,#popup_box1 { 
	display:none; /* Hide the DIV */
	position:fixed;  
	_position:absolute; /* hack for internet explorer 6 */  
	height:350px;  
	width:400px;  
	background:#FFFFFF;  
	left: 300px;
	top: 50px;
	z-index:100; /* Layering ( on-top of others), if you have lots of layers: I just maximized, you can change it yourself */
	margin-left: 15px;  
	
	/* additional features, can be omitted */
	border:2px solid #ffffff;  	
	padding:15px;  
	font-size:15px;  
	-moz-box-shadow: 0 0 5px #ff0000;
	-webkit-box-shadow: 0 0 5px #ff0000;
	box-shadow: 0 0 10px #123456;
	
}



a{  
cursor: pointer;  
text-decoration:none;  
} 

/* This is for the positioning of the Close Link */
#popupBoxClose {
	font-size:20px;  
	line-height:15px;  
	right:5px;  
	top:5px;  
	position:absolute;  
	color:#6fa5e2;  
	font-weight:500;  	
}
{/literal}
</style>
<link rel="stylesheet" type="text/css" href="css/flexigrid.css" />
<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="js/flexigrid.js"></script>
<script type="text/javascript">
{literal}
function loadPopupBox(name) 
{	// To Load the Popupbox
	$(name).fadeIn("slow");
		
}

function unloadPopupBox(name) 
{	// TO Unload the Popupbox
	$(name).fadeOut("slow");
	
}


function doClick1()
{
	var form1 = document.d2;
	var pid = document.getElementById("discountID").value;

		  $.ajax({
		   type: "POST",
		   dataType: "json",
		   url: "?act=discount.modify_discount",
		   data: "items="+pid,
		   success: function(){
		  
			alert("取消成功！");
		   unloadPopupBox('#popup_box1');
		  
		  
		   $("#flex1").flexReload();
		   }
		 });

}

function doClick()
{
	var form1 = document.d1;
	if(form1.amount.value == "")
		alert("请输入具体优惠");
	else {
		//form1.submit();
		//ajax调用
		
		var tmp = form1.type.value+","+form1.amount.value+","+form1.name.value+","+form1.description.value+","+form1.startdate.value+","+form1.enddate.value;
		
		$.ajax({
			   type: "POST",
			   dataType: "json",
			   url: "?act=discount.add_discount",
			   data: "items="+tmp,
			   success: function(data){
				   
			   	   alert("添加成功");
			   	   unloadPopupBox('#popup_box');
			       $("#flex1").flexReload();
			   }
			 });
	}
	
}
$(document).ready(function(){
	
	$("#flex1").flexigrid
			(
			{
				url: '?act=discount.discount_list_show',
				dataType: 'json',

			colModel : [
				{display: 'ID', name : 'ID', width : 40, sortable : true, align: 'center'},
				{display: 'Type', name : 'DiscountType', width : 60, sortable : true, align: 'center'},
				{display: 'Name', name : 'Name', width : 120, sortable : true, align: 'left'},
				{display: 'Description', name : 'Description', width : 180, sortable : true, align: 'left'},
				{display: 'Amount', name : 'Amount', width : 60, sortable : true, align: 'left'},
				{display: 'StartTime', name : 'StartTime', width : 120, sortable : true, align: 'left'},
				{display: 'EndTime', name : 'EndTime', width : 120, sortable : true, align: 'left'},
				{display: 'Status', name : 'Status', width : 60, sortable : true, align: 'left'},
				],
			buttons : [
				{name: 'Add', bclass: 'add', onpress : test},
				{name: 'Delete', bclass: 'delete', onpress : test},
				{name: 'Modify', bclass: 'add', onpress : test},    
				],
			searchitems : [
                
				{display: 'ID', name : 'ID', isdefault: true}
				],
			sortname: "ID",
			sortorder: "asc",
			usepager: true,
			title: '折扣信息',
			useRp: true,
			rp: 10,
			showTableToggleBtn: true,
			width: 'auto',
			height: 'auto',
			gridClass: "bbit-grid",
			procmsg: '正在获取数据，请稍候 ...'  
			}
			);   
	
	
});

function sortAlpha(com)
{ 
    jQuery('#flex1').flexOptions({newp:1, params:[{name:'letter_pressed', value: com},{name:'qtype',value:$('select[name=qtype]').val()}]});
    jQuery("#flex1").flexReload(); 
}

function test(com,grid)
{
    if (com=='Delete')
        {
           if($('.trSelected',grid).length>0){
		   if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){
		 
			var tmp ='';
            
            for(var i=0;i<$('.trSelected',grid).length;i++)
            {  
            	
            		 
            	var a = $('.trSelected',grid).find("td:first").eq(i).text();
            	tmp =tmp+a+",";
            	
            	
            	 
			}
          
            
			$.ajax({
			   type: "POST",
			   dataType: "json",
			   url: "?act=discount.discount_delete",
			   data: "items="+tmp,
			   success: function(data){
			   alert("删除成功");
			   $("#flex1").flexReload();
			   }
			 });
			}
			} else {
				return false;
			} 
        }
    else if (com=='Add')
        {
    	loadPopupBox('#popup_box');
        }      
    else if (com == 'Modify')
    	{
    	 if($('.trSelected',grid).length == 1)
    		 {
    		   var pid = document.getElementById("discountID");
			   pid.value = $('.trSelected',grid).find("td").eq(0).text();
    		   loadPopupBox('#popup_box1');
    		 }
    	 else if($('.trSelected',grid).length == 0)
    		 alert("请选择要修改的信息");
    	 else if($('.trSelected',grid).length >1)
    		 alert("请每次选择一个记录");
    	 
    	}
} 


{/literal}
</script>
<title>Insert title here</title>
</head>
<body>
<!--  
<table>
<th>优惠</th>
<th>名称</th>
{foreach from=$discount_list item=discount}
<tr>
<td>{$discount.dis_name}</td>
<td>{$discount.dis_descrip}</td>
</tr>
{/foreach}
</table>
-->
<div>
<table id="flex1" style="display:none"></table>
</div>




<div id="popup_box">	<!-- OUR PopupBox DIV-->
	<h1>添加打折信息</h1>
	<form name="d1" action="?act=discount.add_discount" method='post'>
<table>
<tr>
<td>打折类型</td>
<td><select name="type">
  <option value ="1">1.打折</option>
  <option value ="2">2.优惠</option>
   <option value ="3">3.团购</option>
  </select></td>
</tr>
<tr>
<td>名称</td>
<td><input type="text" name="name" ></td>
</tr>
<tr>
<td>打折描述</td>
<td><input type="text" name="description" />
</td>
</tr>
<tr>
<td>打折数量  </td>
<td><input type="text" name="amount" ></td>
</tr>
<tr>
<td>开始时间，格式20XX-XX-XX</td>
<td><input type="text" name="startdate" ></td>
</tr>
<tr>
<td>结束时间，格式20XX-XX-XX</td>
<td><input type="text" name="enddate" ></td>
</tr>
</table>
<br>
<br>	
	<input type="button" value="提交" onClick="doClick();">
	</form>
	<a id="popupBoxClose" onClick="unloadPopupBox('#popup_box');">Close</a>	
</div>


<div id="popup_box1">	<!-- OUR PopupBox DIV-->
	<h1>取消优惠？</h1>
	<form name="d2" action="?act=discount.modify_discount" method='post'>
<table>
<tr><td>
<input type="hidden" id="discountID" value=""/>
</td>
</tr>

</table>
<br>
<br>	
	<input type="button" value="提交" onClick="doClick1();">
	</form>
	<a id="popupBoxClose" onClick="unloadPopupBox('#popup_box1')">Close</a>	
</div>


</body>
</html>